﻿//-----------------------------------------------------------------------
// <copyright file="ConversionHelper.cs" company="Streetlight Technologies L.L.C.">
//    Copyright Streetlight Technologies L.L.C. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Streetlight.Store.DataAccess
{
    using System;

    /// <summary>
    /// Provides static methods for type conversions.
    /// </summary>
    public static class ConversionHelper
    {
        /// <summary>
        /// Tries to parse the string provided as an integer.
        /// </summary>
        /// <param name="parameterName">Name of parameter to include in exception on failure.</param>
        /// <param name="value">String containing value to parse as integer.  If parsing fails,
        /// an exception is thrown including the provided parameter name and value.</param>
        /// <returns>Value as integer if parsing is successful, otherwise an exception is thrown.</returns>
        public static int TryParsePositiveInt(string parameterName, string value)
        {
            int result;

            if (!int.TryParse(value, out result))
            {
                throw new InvalidOperationException(string.Format("Value of {0} \"{1}\" is not a valid integer.", parameterName, value));
            }

            return result;
        }
    }
}
